package view.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.shilehui.www.R;

public class StatedTabWidget extends FrameLayout {
	
	private ImageView widgetBackground = null;
	
	private boolean selected = false;
	
	private void initWidget(Context context){
		Drawable image = context.getResources().getDrawable(R.drawable.tab_selected_background);
		widgetBackground = new ImageView(context);
		widgetBackground.setImageDrawable(image);
	}

	public StatedTabWidget(Context context){
		super(context);
	}
	
	public StatedTabWidget(Context context, Drawable icon) {
		super(context);
		if(widgetBackground == null){
			initWidget(context);
		}
		
		this.addView(widgetBackground);
		ImageView iconImageView = new ImageView(context);
		iconImageView.setImageDrawable(icon);
		this.addView(iconImageView, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
		
		if (!selected){
			widgetBackground.setEnabled(false);
		} else {
			widgetBackground.setEnabled(true);
		}
	}
	
	public void setSelected(boolean isSelected){
		if (isSelected != selected){
			selected = isSelected;
			if (!selected){
				widgetBackground.setEnabled(false);
			} else {
				widgetBackground.setEnabled(true);
			}
		}
	}
}
